﻿Imports DAO
Imports DTO
Imports System.Data.OleDb
Imports System.Data
Public Class PhieuKhamBenhDAO
    ' lay du lieu BENH
    Public Function LayLoaiBenh() As DataTable
        Dim query As String
        Dim DTP As New DataProvider()
        query = " select * from BENH "
        Dim dt As New DataTable
        dt = DTP.Datatable_PHONGMACHTU(query)
        Return dt

    End Function
    'Lay du lieu thuoc
    Public Function LayLoaiThuoc() As DataTable
        Dim query As String
        Dim DTP As New DataProvider()
        query = " select * from THUOC "
        Dim dt As New DataTable
        dt = DTP.Datatable_PHONGMACHTU(query)
        Return dt

    End Function
    'lay du lieu don vi
    Public Function LayDonVi() As DataTable
        Dim query As String
        Dim DTP As New DataProvider()
        query = " select * from DONVI "
        Dim dt As New DataTable
        dt = DTP.Datatable_PHONGMACHTU(query)
        Return dt

    End Function
    'lay du lieu cach dung
    Public Function LayCachDung() As DataTable
        Dim query As String
        Dim DTP As New DataProvider()
        query = " select * from CACHDUNG "
        Dim dt As New DataTable
        dt = DTP.Datatable_PHONGMACHTU(query)
        Return dt

    End Function
    'Lay ma phieu
    Public Function LayMaBenhNhan() As DataTable
        Dim query As String
        Dim DTP As New DataProvider()
        query = " select MaBenhNhan,HoTen from DANHSACHKHAMBENH "
        Dim dt As New DataTable
        dt = DTP.Datatable_PHONGMACHTU(query)
        Return dt
    End Function
    Public Function LayMaPhieu() As DataTable
        Dim query As String
        Dim DTP As New DataProvider()
        query = " select MaPhieu,HoTen from PHIEUKHAMBENH pkb,DANHSACHKHAMBENH dskb where pkb.MaBenhNhan=dskb.MABenhNhan"
        Dim dt As New DataTable()
        dt = DTP.Datatable_PHONGMACHTU(query)
        Return dt
    End Function
    Public Function INSERT(ByVal pkb As PhieuKhamBenhDTO) As Integer
        ' ket noi csdl
        Dim DTP As New DataProvider()
        Dim cnn As New OleDbConnection
        cnn = DTP.ConnectDB()
        cnn.Open()
        ''
        ' cau truy van
        ''
        Dim query As String
        query = " insert into PHIEUKHAMBENH(MaBenhNhan,DuDoanLoaiBenh,TrieuChung) values (@a,@c,@d) "
        Dim cmd As New OleDbCommand(query, cnn)
        'truyen du lieu
        Dim para As OleDbParameter
        para = cmd.Parameters.Add("@a", OleDbType.BigInt)
        para.Value = pkb.MaBenhNhan
        'para = cmd.Parameters.Add("@b", OleDbType.BigInt)
        'para.Value = pkb.MABENH
        para = cmd.Parameters.Add("@c", OleDbType.VarChar)
        para.Value = pkb.DuDoanLoaiBenh
        para = cmd.Parameters.Add("@d", OleDbType.VarChar)
        para.Value = pkb.TrieuChung
        ''
        'thuc thi truy van
        Dim i As Integer = cmd.ExecuteNonQuery()
        'dong ket noi 
        cnn.Close()
        If (i > 0) Then
            Return 1 'them thanh công
        Else
            Return 0 'them that bai
        End If


    End Function
    Public Function DELETE(ByVal pkb As PhieuKhamBenhDTO) As Integer
        ' ket noi csdl
        Dim DTP As New DataProvider()
        Dim cnn As New OleDbConnection
        cnn = DTP.ConnectDB()
        cnn.Open()
        ''
        ' cau truy van
        ''

        Dim query As String
        query = " delete from PHIEUKHAMBENH where MaPhieu = @maphieu "
        Dim cmd As New OleDbCommand(query, cnn)
        Dim para As OleDbParameter
        para = cmd.Parameters.Add("@maphieu", OleDbType.BigInt)
        para.Value = pkb.MaPhieu
        Dim temp As Integer
        temp = 0
        temp = cmd.ExecuteNonQuery()
        cnn.Close()
        If (temp > 0) Then
            Return 1
        Else
            Return 0
        End If
    End Function

End Class
